package com.demo.jpa.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
 * JPA配置类
 *
 * @author yueyang
 * @since 2022-02-28 14:44:00
 */
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Data
public abstract class AbstractAuditModel implements Serializable {

  /** 主键 */
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  /** 创建时间 */
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "create_time", nullable = false, updatable = false)
  @CreatedDate
  private Date createTime;

  /** 上次更新时间 */
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "last_update_time", nullable = false)
  @LastModifiedDate
  private Date lastUpdateTime;
}
